package com.ogawa.chair7808.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.RelativeLayout;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.ogawa.chair7808.R;
import com.ogawa.chair7808.adapter.AutoProgramAdapter;
import com.ogawa.chair7808.bean.Massage7808Armchair;
import com.ogawa.chair7808.manager.DataManager;
import com.ogawa.chair7808.view.AutoProgramBean;

import java.util.ArrayList;
import java.util.List;

/**
 *人群专属
 */

public class Layout7808Rqzs extends RelativeLayout{
    RecyclerView recyclerView;
    AutoProgramAdapter adapter = new AutoProgramAdapter();
    public Layout7808Rqzs(Context context) {
        super(context);
        init();
    }

    public Layout7808Rqzs(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    void init(){
        LayoutInflater.from(getContext()).inflate(R.layout.layout_auto_program, this);
        recyclerView = findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        recyclerView.setAdapter(adapter);
        List<AutoProgramBean> autoProgramBeanList = new ArrayList<>();
        autoProgramBeanList.add(new AutoProgramBean(getContext().getString(R.string.zy_masa_nwmt),R.drawable.zymasa_beauty_seletor,"1",""));
        autoProgramBeanList.add(new AutoProgramBean(getContext().getString(R.string.zy_masa_nsjt),R.drawable.zymasa_beauty_seletor,"1",""));
        autoProgramBeanList.add(new AutoProgramBean("老年养身",R.drawable.zymasa_older_seletor,"1",""));
        autoProgramBeanList.add(new AutoProgramBean(getContext().getString(R.string.zy_masa_ydhf),R.drawable.zymasa_ydhf_seletor,"1",""));
        adapter.setNewInstance(autoProgramBeanList);
    }

    public void setSelect() {
        try{
            String modelValue = DataManager.getInst().getDevice7808StateBean().getRunningStatus();
            if (modelValue == null){
                return;
            }
            for (int i = 0; i < adapter.getData().size(); i++) {
                if (modelValue.equals(adapter.getData().get(i).getReceiveCode())) {
                    adapter.getData().get(i).setSelect(true);
                } else {
                    adapter.getData().get(i).setSelect(false);
                }
            }
            adapter.notifyDataSetChanged();
        }catch (Exception e){
            e.printStackTrace();
        }

    }
}
